package com.wnxy.pawnbackgroundsystem.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wnxy.pawnbackgroundsystem.dto.PageDto;
import com.wnxy.pawnbackgroundsystem.dto.channel.ChannelGetDto;
import com.wnxy.pawnbackgroundsystem.entity.Channel;
import com.wnxy.pawnbackgroundsystem.dto.channel.ChannelDto;
import com.wnxy.pawnbackgroundsystem.response.Result;
import com.wnxy.pawnbackgroundsystem.service.IChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 渠道商表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-10-14
 */
@RestController
@RequestMapping("/channel")
@CrossOrigin("*")
@Slf4j
public class ChannelController {
    @Resource
    private IChannelService channelService;

    @PostMapping("findAllChannel")
    public Result findAllChannel(@RequestBody ChannelGetDto channelGetDto){
        log.info("查询渠道商信息功能 参数={}",channelGetDto);
        Channel channel = new Channel();
        if (null != channelGetDto.getChannelDto()) {
            BeanUtils.copyProperties(channelGetDto.getChannelDto(),channel);
        }
        IPage<Channel> channel1 = channelService.findChannel(channelGetDto.getPageDto(), channel);
        return Result.success(Channel.class,channel1);
    }
    @PostMapping("updateChannel")
    public Result updateChannel(@RequestBody ChannelGetDto channelGetDto){
        log.info("修改渠道商信息功能：参数={}",channelGetDto);
        Channel channel = new Channel();
        if (null != channelGetDto.getChannelDto()) {
            BeanUtils.copyProperties(channelGetDto.getChannelDto(),channel);
        }
        Channel channel1 = channelService.updateChannel(channel);
        return Result.success(Channel.class,"修改成功",channel1);
    }
    @PostMapping("addChannel")
    public Result addChannel(@RequestBody ChannelGetDto channelGetDto){
        log.info("添加渠道商信息功：参数= {}",channelGetDto);
        Channel channel = new Channel();
        if (null != channelGetDto.getChannelDto()) {
            BeanUtils.copyProperties(channelGetDto.getChannelDto(), channel);
        }
        Channel channel1 = channelService.addChannel(channel);
        return Result.success(Channel.class,"修改成功",channel1);
    }

}

